#!/bin/sh
JAVA_HOME=/usr/lib/jvm/java-6-sun
DAEMON_HOME=/home/samjung/commons-daemon-1.0.1/bin/jsvc-src
DAEMON_USER=samjung
CRAWLER_HOME=/home/samjung/agent
PID_FILE=$CRAWLER_HOME/crawler.pid

CLASSPATH=\
$CRAWLER_HOME/bin:\
$CRAWLER_HOME/lib/commons-daemon.jar:\
$CRAWLER_HOME/lib/commons-codec-1.3.jar:\
$CRAWLER_HOME/lib/commons-collections-3.2.1.jar:\
$CRAWLER_HOME/lib/commons-logging-1.1.1.jar:\
$CRAWLER_HOME/lib/commons-dbcp-1.2.2.jar:\
$CRAWLER_HOME/lib/log4j-1.2.15.jar:\
$CRAWLER_HOME/lib/mysql-connector-java-5.1.6-bin.jar:\
$CRAWLER_HOME/lib/netty-3.1.0.CR1.jar:\
$CRAWLER_HOME/lib/commons-httpclient-3.1.jar:\
$CRAWLER_HOME/lib/commons-pool-1.4.jar:\
$CRAWLER_HOME/lib/ibatis-2.3.4.726.jar:\
$CRAWLER_HOME/lib/jericho-html-3.1.jar:\
$CRAWLER_HOME/lib/sqlitejdbc-v054.jar:\
$CRAWLER_HOME/lib/js.jar

case "$1" in

	start)
    #
    # Start crawler
    #
    $DAEMON_HOME/jsvc \
    -user $DAEMON_USER \
    -home $JAVA_HOME \
    -wait 10 \
    -pidfile $PID_FILE \
    -outfile $CRAWLER_HOME/startup.log \
    -errfile '&1' \
    -Xms256m -Xmx1024m \
    -cp $CLASSPATH \
    CrawlerWrapper
    #
    # To get a verbose JVM
    #-verbose \
    # To get a debug of jsvc.
    #-debug \
    exit $?
    ;;

  stop)
    #
    # Stop crawler
    #
    sudo $DAEMON_HOME/jsvc \
    -stop \
    -pidfile $PID_FILE \
    CrawlerWrapper
    exit $?
    ;;
#
  *)
    echo "Usage crawler start/stop"
    exit 1;;
esac
